package com.ler.pai.controller;

import com.ler.pai.service.GaoDeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 高德地图 api
 *
 * @author lww
 * @date 2020-01-30 18:52
 */
@Api(value = "/gao_de", description = "高德地图")
@RestController
@RequestMapping("/gao_de")
@Slf4j
public class GaoDeController {

	@Resource
	private GaoDeService gaoDeService;

	@ApiOperation("高德地图 根据关键字查询地址")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "keyword", value = "地点关键字", required = true),
	})
	@PostMapping("/location")
	public String location(String keyword) {
		log.info("GaoDeController_location_keyword:{}", keyword);
		Assert.isTrue(StringUtils.isNotBlank(keyword), "参数错误，关键字为空！");
		String locationByKeyword = gaoDeService.getLocationByKeyword(keyword);
		log.info("GaoDeController_location_locationByKeyword:{}", locationByKeyword);
		return locationByKeyword;
	}

	@ApiOperation("高德地图 查询天气（为简化开发，只有 北京，杭州的 天气查询）")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "cityName", value = "城市名字 如 杭州", required = true),
	})
	@PostMapping("/weather")
	public String getWeather(String cityName) {
		log.info("GaoDeController_getWeather_cityName:{}", cityName);
		String serviceWeather = gaoDeService.getWeather(cityName);
		log.info("GaoDeController_getWeather_serviceWeather:{}", serviceWeather);
		return serviceWeather;
	}

	@ApiOperation("高德地图 根据ip获取地址")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "ip", value = "ip地址", required = true),
	})
	@PostMapping("/IP/address")
	public String getIpAddress(String ip) {
		log.info("GaoDeController_getIPAddress_ip:{}", ip);
		Assert.isTrue(StringUtils.isNotBlank(ip), "参数错误，ip为空！");
		String res = gaoDeService.getIPAddress(ip);
		log.info("GaoDeController_getIPAddress_res:{}", res);
		return res;
	}

}
